package factory;

import service.OperationService;
import service.impl.OperationAdd;
import service.impl.OperationDiv;
import service.impl.OperationMul;
import service.impl.OperationSub;

//工厂类
public class OperationFactory {
    //根据用户输入的操作符创建按相应的算法实例并返回
    public static OperationService createOperaction(String operation){
        OperationService operaction=null;
        switch (operation){
            case "+":
                operaction=new OperationAdd();
                break;
            case "-":
                operaction=new OperationSub();
                break;
            case "*":
                operaction=new OperationMul();
                break;
            case "/":
                operaction=new OperationDiv();
                break;
        }
        return operaction;
    }
}
